#!/bin/bash
  
/sbin/ip link delete virbr1 type bridge && /sbin/ip link delete virbr1-nic
declare -i i=0
while [ ! -e /var/run/libvirt/libvirt-sock ];do
        sleep .5
        let i++
        if [ $i -ge 10 ];then
                echo "libvirt-sock do not exist!"
                exit 2
        fi
done
let i=0
/usr/bin/virsh net-destroy virnet1 &> /etc/null
/usr/bin/virsh net-start virnet1
while [ $? -ne 0 ];do
        sleep .5
        /usr/bin/virsh net-start virnet1
        let i++
        if [ $i -ge 10 ];then
                echo "net-start virnet1 failed!"
                exit 2
        fi
done
let i=0
/usr/sbin/netplan apply
sleep .5
/sbin/ip link set eth0 master virbr1
while [ $? -ne 0 ];do
        sleep .5
        /sbin/ip link set eth0 master virbr1
        let i++
        if [ $i -ge 10 ];then
                echo "set etho master virbr1 failed!"
                exit 2
        fi
done